{
open Parser
open Parseutils
open Errors
} 

rule token = parse
    [' ' '\t']                                 {token lexbuf}
  | '\n'                                       {inc_line (); token lexbuf}
  | '('                                        {LPAREN}
  | ')'                                        {RPAREN}
  | "[||]"                                     {ENDF}
  | "[RR]"                                     {ENDRECORD}
  | "[|"                                       {LFUN}
  | "|]"                                       {RFUN}
  | "[R"                                       {LRECORD}
  | "R]"                                       {RRECORD}
  | "(*"                                       {comment lexbuf}
  | ':'                                        {COLON}   
  | '+'                                        {PLUS} 
  | '-'                                        {MINUS}
  | '*'                                        {TIMES}
  | '/'                                        {DIV}
  | '%'                                        {MOD}
  | '<'                                        {LE}
  | "<="                                       {LEQ}
  | '='                                        {EQ}
  | "<>"                                       {NEQ}
  | '>'                                        {GE}
  | ">="                                       {GEQ}
  | "true"                                     {TRUE}
  | "false"                                    {FALSE}
  | '('                                        {LPAREN}
  | ')'                                        {RPAREN}
  | ";"                                        {SEMICOLON}
  | ","                                        {COMMA}
  | ":="                                       {ASSIGNMENT}
  | "."                                        {MEMBER}
  | "and"                                      {AND}
  | "or"                                       {OR}
  | "if"                                       {IF}
  | "then"                                     {THEN} 
  | "else"                                     {ELSE}
  | "begin"                                    {BEGIN}
  | "end"                                      {END}
  | "while"                                    {WHILE}
  | "do"                                       {DO}
  | "var"                                      {VAR}
  | "int"                                      {INTEGER}
  | "bool"                                     {BOOLEAN}
  | "void"                                     {VOID}
  | "forward"                                  {FORWARD}
  | "new"                                      {NEW}
  | "nil"                                      {NIL}
  | "~"                                        {NOT}
  | ['A'-'z'](['A'-'z'] | ['0'-'9'])* as id    {IDENT(id)}
  | ['0'-'9']+ as n                            {INT(int_of_string n)}
  | eof                                        {EOF}
  | ['0'-'9'](['A'-'z'] | ['0'-'9'])*          {raise Bad_ident}
and comment = parse
  | "*)"   {token lexbuf}
  | '\n'   {inc_line (); comment lexbuf}
  | _      {comment lexbuf}
  | eof    {raise Wrong_eof}


